package cn.dujc.superkid.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dujc.superkid.R;
import cn.dujc.superkid.activities.PayActivity;
import cn.dujc.superkid.bean.VIPResult;

/**
 * Created by Administrator on 2018/10/29 0029.
 */

public class VipListAdapter extends RecyclerView.Adapter<VipListAdapter.ViewHolder> {
    private List<VIPResult> datas;
    private Context context;

    public VipListAdapter(Context context) {
        this.context = context;
    }

    public void setDatas(List<VIPResult> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_viplist,null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
      holder.vipName.setText(datas.get(position).getName());
      holder.vipPrice.setText(datas.get(position).getPrice());
      holder.kaitongBtn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent intent =new Intent(context,PayActivity.class);
              intent.putExtra("product_id",datas.get(position).getId())
                   .putExtra("time",datas.get(position).getName())
                   .putExtra("price",datas.get(position).getPrice());
              context.startActivity(intent);

          }
      });
    }

    @Override
    public int getItemCount() {
        return datas==null?0:datas.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView vipName;
        TextView vipPrice;
        TextView kaitongBtn;
        public ViewHolder(View itemView) {
            super(itemView);
            vipName=itemView.findViewById(R.id.item_vip_list_name);
            vipPrice=itemView.findViewById(R.id.item_vip_list_price);
            kaitongBtn=itemView.findViewById(R.id.item_vip_list_kaitong);
        }
    }
}
